package com.chao.yyks;

import com.alibaba.fastjson.JSONObject;
import com.chao.common.config.initialize.Initialize;
import com.chao.common.util.AddressConstant;
import org.apache.commons.io.IOUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

@RestController
@ComponentScan(basePackages = {"com.chao.*"})
@SpringBootApplication(scanBasePackages={"com.chao.*"})
@MapperScan(basePackages = {"com.chao.*.modular.**.mapper"})
public class BusinessApplication implements CommandLineRunner {

	@Value("classpath:address.json")
	private Resource address;

	// nohup java -jar -Dspring.profiles.active=dev xyxa.jar > /dev/null 2>&1 &
	// nohup java -jar -Dspring.profiles.active=pro xyxa.jar > /dev/null 2>&1 &
	public static void main(String[] args) {
		Initialize.init();
		SpringApplication.run(BusinessApplication.class, args);
	}

	@Override
	public void run(String... strings) {
		try {
			String areaData = IOUtils.toString(address.getInputStream(), StandardCharsets.UTF_8);
			AddressConstant.setAddress(JSONObject.parseObject(areaData));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
